uniform float time;

void main()
{
  vec3 x, n, l;
  float ndotl;

  vec4 v = gl_Vertex;
  float z = 0.5*v.z;
  float c = cos(z*sin(0.02*time)), s = sin(z*sin(0.02*time));

  mat4 rz = mat4(c,-s,0,0,s,c,0,0,0,0,1,0,0,0,0,1);
  v = rz*v;

  /* inverse transpose of a rotation matrix is itself */
  mat3 irz = mat3(c,-s,0,s,c,0,0,0,1);

  x = vec3(gl_ModelViewMatrix * gl_Vertex);
  n = normalize(gl_NormalMatrix * irz * gl_Normal);
  l = normalize(vec3(gl_LightSource[0].position) - x);
  ndotl = max(dot(n,l),0.0);
  gl_FrontColor = gl_FrontMaterial.diffuse * gl_LightSource[0].diffuse * ndotl;

  gl_Position = gl_ModelViewProjectionMatrix * v;
}
